﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PalcoCentral
{
    public partial class pcLogin : Form
    {
        public pcLogin()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            passEditText.PasswordChar='*';
            passEditText.MaxLength = 12;
        }

        private void lginSairBut_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void lginOkBut_Click(object sender, EventArgs e)
        {
            string userLogin = loginEditText.Text;
            string passLogin = passEditText.Text;
            Library.OperationStatus os = Database.PersonDBAdapter.getInstance().Authenticate(userLogin, passLogin);

            if (os.sucess){
                pcGestorPrincipal verListaPessoas = new pcGestorPrincipal((Database.person)os.res);
                verListaPessoas.FormClosed += new FormClosedEventHandler(child_FormClosed);
                verListaPessoas.Show();
                this.Hide();
            }
            else {
                wrongPassLabel.Text = "Login e/ou password incorrectos!";
                passEditText.ResetText();
            }
        }

        void child_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Close();
        }


     

    }
}
